﻿using System.Threading.Tasks;
using Xproject.Framework.Core;
using Xproject.Framework.Core.DataContext;
using Xproject.Framework.Core.Repositories;
using Model.Util;
using Model.Const;
using Repository.Util;
using Xproject.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Model.Util.DTO;

namespace Services.Util
{
   public  class UserOperateServices : Service
    {
        IRepositoryAsync<UserOprateLog> UserOprateLogRepository;
        public UserOperateServices(IDataContextAsync dataContext) : base(dataContext)
        {
            UserOprateLogRepository = m_UnitOfWork.RepositoryAsync<UserOprateLog>();
        }

        public void AddOperateLogContent(EnumOperateType type, string UserId, string RefId, string Domain, string refUrl, string remarks)
        {
            UserOprateLog log = new UserOprateLog();
            log.CreateTime = DateTime.Now;
            log.Domain = Domain;
            log.LogID = Guid.NewGuid().ToString();
            log.OprateName = type.ToString();
            log.OprateType = (int)type;
            log.RefID = RefId;
            log.RefUrl = refUrl;
            log.Remark = remarks;
            log.UserID = UserId;
            log.EntityState = EntityState.Added;
            UserOprateLogRepository.Insert(log);        
        }

        public List<UserOperateLogModel> GetMyBrowserHistory(int? offset, int? limit, string userId)
        {
            return UserOprateLogRepository.GetMyBrowserHistory(offset.Value, limit.Value, userId,(int)EnumOperateType.浏览产品);
        }
         

        public bool AddOperateLog(EnumOperateType type, string UserId, string RefId, string Domain, string refUrl, string remarks)
        {
            AddOperateLogContent(type, UserId, RefId, Domain, refUrl, remarks);
           return  m_UnitOfWork.SaveChanges()==1;
        }
    }
}
